package com.example.web.controller;

import com.example.web.pojo.Result;
import com.example.web.pojo.User;
import com.example.web.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    // 查询所有用户
    @GetMapping("/selectAll")
    public Result selectAll() {
        return userService.selectAll();
    }

    // 根据用户名查询用户
    @GetMapping("/selectByName")
    public Result selectByName(String name) {
        return userService.selectByName(name);
    }

    // 添加用户
    @PostMapping("/insert")
    public Result insert(@RequestBody User user) {
        return userService.insert(user);
    }

    // 修改用户
    @PostMapping("/update")
    public Result update(@RequestBody User user) {
        return userService.update(user);
    }

    // 删除用户
    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id) {
        return userService.deleteById(id);
    }

    //更新用户信息
    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody User user) {
        return userService.update(user);
    }
}
